package com.jams.goodox.activity.serve.headhunter;

import android.view.View;
import android.widget.RelativeLayout;

import com.jams.goodox.BaseActivity;
import com.jams.goodox.R;
import com.jams.goodox.entity.ResumeBean;
import com.jams.goodox.entity.resp.ResumeDetailResp;
import com.jams.goodox.net.RetrofitCallbackListener;
import com.jams.goodox.net.services.HeadHunterService;
import com.jams.goodox.utils.permission.PhoneUtils;
import com.jams.goodox.utils.ProgressDialogUtils;
import com.jams.goodox.utils.StyleUtil;
import com.jams.goodox.widget.LRTextView;

import butterknife.Bind;
import butterknife.OnClick;
import retrofit2.Call;

/**
 * 简历详情页
 * <p>
 * create by 顾佳佳 on 2017/05/16
 */
public class ResumeDetailActivity extends BaseActivity {

    public static final String ID = "ID";
    @Bind(R.id.lr_resume_name)
    LRTextView lrResumeName;
    @Bind(R.id.lr_resume_sex)
    LRTextView lrResumeSex;
    @Bind(R.id.lr_resume_marry)
    LRTextView lrResumeMarry;
    @Bind(R.id.lr_resume_work_time)
    LRTextView lrResumeWorkTime;
    @Bind(R.id.lr_resume_company)
    LRTextView lrResumeCompany;
    @Bind(R.id.lr_resume_job)
    LRTextView lrResumeJob;
    @Bind(R.id.lr_resume_graduation_school)
    LRTextView lrResumeGraduationSchool;
    @Bind(R.id.lr_resume_specialty)
    LRTextView lrResumeSpecialty;
    @Bind(R.id.lr_resume_graduation_education)
    LRTextView lrResumeGraduationEducation;
    @Bind(R.id.lr_resume_graduation_phone)
    LRTextView lrResumeGraduationPhone;
    @Bind(R.id.lr_resume_graduation_email)
    LRTextView lrResumeGraduationEmail;
    @Bind(R.id.rl_resumen_all)
    RelativeLayout rlResumeAll;
    private String resumeId;
    private ResumeBean resumeBean;
    private PhoneUtils phoneUtils;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_resume_detail;
    }

    @Override
    protected void init() {
        StyleUtil.titleBackKey(this, "简历详情");
        resumeId = getIntent().getStringExtra(ID);
        phoneUtils = new PhoneUtils(this);
        getResumeDetail();
    }

    private void getResumeDetail() {
        ProgressDialogUtils.show(this);
        enqueue(createCallService(HeadHunterService.class).getResumeDetail(resumeId), new RetrofitCallbackListener<ResumeDetailResp>() {
            @Override
            public void onSuccess(Call<ResumeDetailResp> call, ResumeDetailResp result) {
                ProgressDialogUtils.dismiss();
                resumeBean = result.getData();
                setData();
            }

            @Override
            public void onError(String msg) {
                ProgressDialogUtils.dismiss();
            }
        });
    }

    private void setData() {
        if (resumeBean == null) {
            return;
        }
        rlResumeAll.setVisibility(View.VISIBLE);
        lrResumeName.setTvRight(resumeBean.getName());
        lrResumeSex.setTvRight(resumeBean.getSexStr());
        lrResumeMarry.setTvRight(resumeBean.getMarriage());
        lrResumeWorkTime.setTvRight(resumeBean.getJobLife());
        lrResumeCompany.setTvRight(resumeBean.getCompany());
        lrResumeJob.setTvRight(resumeBean.getPosition());
        lrResumeGraduationSchool.setTvRight(resumeBean.getSchool());
        lrResumeSpecialty.setTvRight(resumeBean.getMajor());
        lrResumeGraduationEducation.setTvRight(resumeBean.getEducation());
        lrResumeGraduationPhone.setTvRight(resumeBean.getConnection());
        lrResumeGraduationEmail.setTvRight(resumeBean.getEmail());
    }

    @OnClick(R.id.lv_job_call)
    public void onViewClicked() {
        if(resumeBean == null){
            return;
        }
        phoneUtils.makeCall(resumeBean.getName(), resumeBean.getConnection());
    }
}
